#ifndef NW_UTILITY_H
#define NW_UTILITY_H

/**
 * Utility functions for queue handling
 */
// utility function for locating a packet in a queue by the sequence num
//PACKET *get_pkt_by_seq(NW_QUEUED_PKT **, const uint32_t);

// Initialize new queue for given node addr, add to queue list
static NW_QUEUE *new_nw_queue(const unsigned char, NW_QUEUE **);

static void qpkt_append(VECTOR, NW_QUEUED_PKT *);

static void qpkt_insert(VECTOR, NW_QUEUED_PKT *, const uint16_t);

static NW_QUEUED_PKT *qpkt_pop(VECTOR);

static bool qpkt_empty(VECTOR);

static bool qpkt_full(VECTOR);

static int get_qpkt_pos_by_seq(VECTOR, const uint32_t);

static int get_qpkt_insert_pos_by_seq(VECTOR, const uint32_t);

// Return queue element for given node addr
static NW_QUEUE *get_queue_by_addr(const unsigned char, NW_QUEUE *);

static NW_QUEUED_PKT *get_qpkt_by_pos(VECTOR, const uint16_t);

static void ack_append(VECTOR, ACK_PENDING *);

static ACK_PENDING *ack_pop(VECTOR);

static bool ack_empty(VECTOR);

static uint16_t pkt_crc(PACKET *);

/*
static NW_QUEUE *new_nw_queue(const CnetAddr addr, NW_QUEUE *last) {
	NW_QUEUE *q = malloc(sizeof(NW_QUEUE));
	
	memset(q, 0, sizeof(NW_QUEUE));

	q->addr = addr;
	q->next_seq = 1;
	
	if (last == NULL)
		last = q;
	else
		last->next = q;
		
	return q;
}

static NW_QUEUE *nw_queue_tail(NW_QUEUE *head) {
	NW_QUEUE *q = head;

	while (q->next != NULL)
		q = q->next;

	return q;
}

static NW_QUEUE *get_queue_by_addr(const CnetAddr addr, NW_QUEUE *head) {
	NW_QUEUE *q = head;
	
	while (q != NULL) {
		if (q->addr == addr)
			return q;
		q = q->next;
	}
	
	return NULL;
}

static ACK_QUEUE *new_ack(ACK_QUEUE *last) {
	ACK_QUEUE *q = malloc(sizeof(ACK_QUEUE));

	if (last == NULL)
		last = q;
	else
		last->next = q;

	return q;
}

static ACK_QUEUE *ack_queue_tail(ACK_QUEUE *head) {
	ACK_QUEUE *q = head;

	while (q->next != NULL)
		q = q->next;

	return q;
}

static ACK_QUEUE *get_ack_by_addr(const CnetAddr addr, ACK_QUEUE *head) {
	ACK_QUEUE *q = head, *last = NULL;

	while (q != NULL) {
		if (q->addr == addr) {
			if (last != NULL)
				last->next = q->next;
			return q;
		}
		last = q;
		q = q->next;
	}

	return NULL;
}


void NW_ack_timeouts(CnetEvent ev, CnetTimerID timer, CnetData data) {
	PACKET *pkt = (PACKET *)data;

	NW_route_packet(pkt);
}
*/
#endif
